package com.maxjay.system.dao.hibernate;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.maxjay.system.dao.UserDao;
import com.maxjay.system.po.TSysUser;

@SuppressWarnings("unchecked")
public class UserDaoHibernate extends BaseDaoHibernate implements UserDao {

	public void deleteUser(String userId) {
		TSysUser user = (TSysUser) this.load(TSysUser.class, userId);
		this.delete(user);
	}

	public TSysUser getUser(String userId){
		return (TSysUser)this.get(TSysUser.class, userId);
	}

	public List<TSysUser> findUser(String loginId, String password) {
		DetachedCriteria dc = DetachedCriteria.forClass(TSysUser.class)
			.add(Restrictions.eq("loginId", loginId))
			.add(Restrictions.eq("password", password));
		return this.findByCriteria(dc);
	}

	public List<TSysUser> getAllUsers() {
		DetachedCriteria dc = DetachedCriteria.forClass(TSysUser.class);
		return this.findByCriteria(dc);
	}
	
	public List<String> getAllUserIds() {
		String hql = "select u.objId from TSysUser u";
		return this.getHibernateTemplate().find(hql);
	}

	public List<TSysUser> findUser(String loginId) {
		DetachedCriteria dc = DetachedCriteria.forClass(TSysUser.class).add(Restrictions.eq("loginId", loginId));
		return this.findByCriteria(dc);
	}

}
